package ogdkp.providers;

import ogdkp.om.ITreeNode;

import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;

public class DKPContentProvider implements ITreeContentProvider {
	@Override
	public void inputChanged(final Viewer v, final Object oldInput, final Object newInput) {
	}

	@Override
	public void dispose() {
	}

	@Override
	public Object[] getElements(final Object parent) {
		if (parent instanceof Object[]) {
			return (Object[]) parent;
		}
		return new Object[0];
	}

	@Override
	public Object[] getChildren(final Object parentElement) {
		if (parentElement instanceof ITreeNode) {
			return ((ITreeNode) parentElement).getChildren().toArray();
		}
		return null;
	}

	@Override
	public Object getParent(final Object element) {
		if (element instanceof ITreeNode) {
			return ((ITreeNode) element).getParent();
		}
		return null;
	}

	@Override
	public boolean hasChildren(final Object element) {
		if (element instanceof ITreeNode) {
			return ((ITreeNode) element).getChildren().size() > 0;
		}
		return false;
	}
}
